package top.humbleyuan.linkedlist;

import top.humbleyuan.datastructure.linkedlist.LinkNode;
import top.humbleyuan.datastructure.linkedlist.MyEntry;

import java.util.Arrays;
import java.util.Stack;

/**
 * @Author HumbleYuan
 * @Date 2020/5/18 22:48
 * @Des 链表中下一个更大节点
 */
public class LeetCode_1019 {
    public static void main(String[] args) {
        /**
         * 数据准备
         */
        LinkNode head = new LinkNode(2);
        int[] vals = {1,5};
        head = LinkNode.formLink(head,vals);

        Stack<MyEntry<Integer,Integer>> stack = new Stack<>();
        int[] largerArray = new int[10000];

        LinkNode temp = head;
        int length = 0;

        while (temp != null) {
            if(!stack.empty() && temp.val > stack.peek().getValue()) {
                largerArray[stack.peek().getKey()] = temp.val;
                stack.pop();
                continue;
            }
            stack.push(new MyEntry<>(length,temp.val));
            temp = temp.next;
            length ++;
        }

        Arrays.copyOfRange(largerArray,0,length);
    }
}
